home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_12 / pugh / dummy.cpp < prev   
Encoding:
C/C++ Source or Header  |  1994-09-26  |  999 b   |  45 lines

  1. Listing 1
  2. ***********
  3.  
  4. #include        <string.h>
  5. #include        <iostream.h>
  6.  
  7. class ClassOne
  8.     {    
  9.      char string[35]; 
  10. public: 
  11.      char Second_string[35];
  12.     
  13.      friend ostream &operator<<(ostream &Xstream, ClassOne objX); 
  14.      ClassOne(char *s1);  
  15.      ClassOne(char *s1,int x);
  16.     };                                             
  17.  
  18. ClassOne::ClassOne(char *s1)
  19.      {
  20.      strcpy(string,s1); 
  21.      } 
  22.  
  23. ClassOne::ClassOne(char *s1,int x)
  24.      {
  25.        strcpy(Second_string,s1);
  26.        x = 0; // avoid warning about unreferenced variable
  27.      } 
  28.  
  29. ostream &operator<<(ostream &Xstream, ClassOne & objX)     
  30.      {
  31.        Xstream << objX.string;
  32.        return(Xstream);
  33.      } 
  34.  
  35. void main(void)
  36.      {
  37.      ClassOne objY("Read C-User's Journal \n");       
  38.      ClassOne objZ("How to overload the << twice ?",NULL); 
  39.      cout << objY;
  40.      // cout << objZ;  // does not work !  
  41.      cout << objZ.Second_string;  
  42.      }
  43.  
  44. /* End of File */
  45.